
<?php
/* @var $model Invoice */
?>

<?php 
$hold = !!$model->hold;
$invoiceAttributes = json_encode($model->attributes);
if($hold){
	$hold  ='true';
	}else $hold = 'false';
Yii::app()->clientScript->registerScript('info', <<<HERE
            var type='$type';
          
            itemPriceCode='{$model->pricecode}';
            var custno='$model->custno';
            invoice='$model->invoice';    
            var editable=0;
               var hold=$hold;
                   var invoiceModel = $invoiceAttributes;
HERE
        , CClientScript::POS_HEAD); 
            
            Yii::app()->clientScript->registerScriptFile('js/jquery.inlineedit.js', CClientScript::POS_HEAD);
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/invoicetechnician.js', CClientScript::POS_BEGIN);
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/invoicesItems.js', CClientScript::POS_BEGIN);
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/invoicesTransactions.js', CClientScript::POS_BEGIN);
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/invoicesFunctions.js', CClientScript::POS_BEGIN);
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/invoiceupdate.js', CClientScript::POS_BEGIN);
            ?>



<div id="left-col">
    <?php
    $this->renderPartial('_side', array(
        'location' => $model->location,
        'customer' => $model->location->customer,
        'action' => 'view',
        'model' => $model,
        'type' => $type
    ));
    ?>


</div>

<div id="right-col">

    <div class="wrap">
        <div class="container">


            <div id="breadcrumb" style="display:none;"><span style="padding-left:10px;font-size:10px;color:#777777;" id="alsoviewing"></span></div>
            <div class="inside">
                <?php
                $form = $this->beginWidget('CActiveForm', array(
                    'id' => 'invoice-form',
                    'enableAjaxValidation' => true,
                        ));
                ?>
                <h1>Update <?= $type ?>: <?= $model->invoice ?> 

                    <?php if ($model->invoicetype == Invoice::TYPE_INVOICE && $model->checkPaid()): ?>
                        <img src="images/paid.png" alt="Paid"/>
                    <?php endif ?>
                    <?php if ($model->invoicetype == Invoice::TYPE_QUOTE): ?>
                        <?php if ($model->quotestatus == Invoice::STATUS_APPROVED): ?>
                            <img src="images/approved.png" alt="Approved"/>
                        <?php elseif ($model->quotestatus == Invoice::STATUS_REJECTED): ?>
                            <img src="images/rejected.png" alt="Rejected"/>
                        <?php endif ?>
                    <?php endif ?>

                </h1>
                <br/>
                <?php
                if ($model->invoicetype == Invoice::TYPE_CREDIT_MEMO) {
                    echo CHtml::tag('b', array(), 'Credit Memo for Invoice No: ' . $model->invoiceorg);
                }
                if ($model->invoicetype == Invoice::TYPE_SALES_ORDERS) {
                    echo CHtml::tag('b', array(), 'Quote Reference: ' . $model->quoteorg);
                    echo '<br/>';
                }
                if ($model->invoicetype == Invoice::TYPE_INVOICE) {
                    echo CHtml::tag('b', array(), 'Sales Order Reference: ' . $model->salesordersorg);
                    echo '<br/>';
                }
                ?>

                <div class="form">



                    <div class="row" style="height:80px">
                        <table style=" width: 755px;">
                            <tr>
                                <td style=" width: 363px;">
                                    <?php echo $form->labelEx($model, 'billloc', array('style' => 'width: 100px;')); ?>
                                    <br clear="all"/>
                                    <?php
                                    $customer = Customers::model()->findByPk($model->custno);

                                    $data = $model->getBillToList($model->location->custno);
                                    ?>
                                    <div class="model-data" style="width:500px">
                                        <?= $data[$model->billloc] ?>
                                    </div>

                                    <br clear="all"/>
                                    <span id='billadd1'></span><br/>
                                    <span id='billadd2'></span><br/>
                                    <span id='billcsz'></span><br/>
                                </td>
                                <td >

                                    <label>Ship To</label>

                                    <br clear="all"/>
                                    <div class="model-data">
                                        <?= $model->shipname ?>
                                    </div>
                                    <br clear="all"/>
                                    <?= $model->shipaddress1 ?><br/>
                                    <?= $model->shipaddress2 ?><br/>
                                    <?= $model->shipCSZ ?><br/>
                                </td>

                            </tr>
                        </table>

                    </div>
                    <br clear="both"/>  <br clear="both"/> <br clear="both"/>
                    <div class="left-column">
                        <div class="row short">
                            <label><?= $type ?> Number</label>
                            <div class="model-data">
                                <?php echo $model->invoice; ?>
                            </div>




                        </div>
                        <div class="row short">
                            <label><?= $type ?> Date</label>
                            <div class="model-data">
                                <?php echo $model->invoicedate; ?>
                            </div>




                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'department'); ?>
                            <div class="model-data">
                                <?php echo $model->departments[$model->department]; ?>
                            </div>


                        </div>
                           <div class="row short" style="white-space: nowrap;">
                         		<?php $ifExempt = $model->getLocation()->isexempt ==Locations::TAX_EXEMPT_YES?>
								<?php if($model->version == 1):?>
                         <label>  Tax Rate: </label> 
                          <div class="model-data">
                      <?=$model->getTaxModel()->state?>  <?=$model->getTaxModel()->salestaxrate ?> %
                         <?php if($ifExempt): ?>
                                    Location is exempt
                                    <?php endif; ?>
     </div>
                               <?php else:?>
                                 <?php if(!$model->checkNex()): ?>
                                  <label>  Tax Rate: </label> 
                                    <div class="model-data">
                                   <?php echo $model->getTaxModelByZip($model->getLocation()->zip)->state ;?> 
                                 <?=$model->getTaxModelByZip($model->getLocation()->zip)->salestaxrate?> %
                                    <?php if($ifExempt): ?>
                                  Location is exempt
                                    <?php endif; ?>
                                 </div>
                                  <?php else :?>
                                 <label>Nex Tax Rate: </label> 
                                   <div class="model-data">  <?=$model->getTaxModel()->state?> <?=$model->getTaxModel()->salestaxrate ?> %  
                                      <?php if($ifExempt): ?>
                                  Location is exempt
                                    <?php endif; ?>
                                   </div>
                                <?php endif;?>
                               <?php endif;?>
                             
                         


                        </div>

                        <div class="row short">
                            <?php echo $form->labelEx($model, 'jobnumber'); ?>
                            <div class="model-data">
                                <?php
                                if ($model->jobnumber != NULL) {
                                    $jobList = Jobs::getList();
                                    echo $jobList[$model->jobnumber];
                                }
                                ?>
                            </div>



                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'ponumber'); ?>
                            <div class="model-data">
                                <?php echo $model->ponumber; ?>
                            </div>
                        </div>
                                                  <div class="row short">
                            <?php echo $form->labelEx($model, 'version'); ?>
                            <div class="model-data">
								<?=$model->version?>
                            </div>
                            <?php echo $form->error($model, 'version'); ?>

                           

                        </div>
                       
                        <div class="row short" id="dispatch" style="">
                            <?php echo $form->labelEx($model,'dispatch');?>
                            <div class="model-data">
                                <?php echo $model->dispatch; ?>
                            </div>
                        </div>

                    </div>
                    <div class="right-column">
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'agreementno'); ?>
                            <div class='model-data'><?php echo $model->agreementno; ?></div>
                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'pricecode'); ?>
                            <div class='model-data'><?php echo $model->pricecode; ?></div>

                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'salesperson'); ?>
                            <div class="model-data">
                                <?php
                                $data = Customers::model()->getSalePersonList();
                                echo $data[$model->salesperson];
                                ?>
                            </div>
                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'clerk'); ?>
                            <div class="model-data">
                                <?php echo Employees::getEmployeeName($model->clerk); ?>
                            </div>

                        </div>
                        <div class="row short">
                            <?php echo $form->labelEx($model, 'slterms'); ?>
                            <div class="model-data">
                                <?php
                                $termList = Customers::model()->getTermList();
                                echo $termList[$model->slterms];
                                ?>
                            </div>
                        </div>
                        <div class="row short">
                                <?php echo $form->labelEx($model, 'purchasedby'); ?>
                            <div class="model-data">
                            <?php echo $model->purchasedby; ?>
                            </div>
                        <?php echo $form->error($model, 'purchasedby'); ?>
                        </div>
<?php if ($model->invoicetype == Invoice::TYPE_QUOTE): ?>
                            <div class="row short">
                                <label><?= $type ?> status</label>
                                <div class="model-data">
                                <?php echo $model->getQuoteStatusText(); ?>
                                </div>
    <?php echo $form->error($model, 'quotestatus'); ?>
                            </div>

                            <?php
                            $style = $model->quotestatus != Invoice::STATUS_REJECTED ? 'display:none' : NULL;
                            ?>
                            <div id="rejectedreason" style="<?= $style ?>">

                                <div class="row short">
                                    <?php echo $form->labelEx($model, 'rejectedreason'); ?>
                                    <?php echo $form->textArea($model, 'rejectedreason', array('style' => 'width:500px;')); ?>
    <?php echo $form->error($model, 'rejectedreason'); ?>
                                </div>

                            </div>
<?php elseif ($model->invoicetype == Invoice::TYPE_SALES_ORDERS): ?>
                            <div class="row short">
                                <label>Sales Order status</label>
                                <div class="model-data">
                                <?php echo JobsStatus::getText($model->salesorderstatus); ?>
                                </div>
                            <?php echo $form->error($model, 'salesorderstatus'); ?>
                            </div>
<?php endif ?>
                    </div>



                    <br clear="both"/>

                </div>
                <table style="width:700px">
                    <tr>
                        <td>Dispatch</td>
                        <td><?= $model->dispatch ?></td>
                        <td>Discount</td>
                        <td>0.00</td>
                        <td>Balance</td>
                        <td>0.00</td>
                    </tr>
                    <tr>
                        <td>Regular Hours</td>
                        <td id="regularhours"><?= InvoiceEmp::model()->getTotalRegularHours($model->invoice) ?></td>
                        <td></td>
                        <td></td>
                        <td>Over 30</td>
                        <td>0.00</td>              
                    </tr>
                    <tr>
                        <td>Overtime</td>
                        <td id="overhead"><?= InvoiceEmp::model()->getTotalRegularHours($model->invoice) ?></td>
                        <td></td>
                        <td></td>
                        <td>Over 60</td>
                        <td>0.00</td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>Over 90</td>
                        <td>0.00</td>
                    </tr>
                </table>

                <br/>
                <ul id="tab" class="tabs tabs-with-summary">
                    <li class="active"><a href="#invoice">Item List</a></li>
                    <li><a href="#technician">Technician</a></li>
                      <li><a href="#transactions">Transactions</a></li>
                    <li><a href="#equipment" class='unavailable'>Equipment</a></li>
                    <li><a href="#document" class='unavailable'>Document</a></li>
                </ul>

                <br/>   
                <div id="invoice">

                    <div id="item-list">

                    </div>
                </div>
                <div id="technician">

                    <div id="emp-list"></div>
                </div>
                   <div id="transactions">
                    <div id="trans-list">

                    </div>

                </div>
                <div id="equipment"></div>
                <div id="document"></div>
                <br/>

                <div class="form">
                    <div class="left-column" style="">
                            <?php if ($model->invoicetype == INVOICE::TYPE_INVOICE): ?>
                            <div class="row short">
                                    <?php echo $form->labelEx($model, 'hold'); ?>
                                <div class="model-data">
                                    <?php
                                    $holdList = $model->getHoldList();
                                    echo $holdList[$model->hold];
                                    ?>
                                </div>

                            </div>
                             <div class="row short">
                            <?php echo $form->labelEx($model, 'postedQuickBook'); ?>
                            <div class="model-data">
                                <?php echo $model->getPostedQuickBookText(); ?>
                            </div>
                        </div>
<?php endif ?>




                    </div>

                    <div class="right-column" style="float:right;">

                        <?php
                        $this->renderPartial('_summary', array(
                            'invoice' => $model
                        ));
                        ?>

                    </div>

                </div>

    <?php $this->endWidget('CActiveForm'); ?>
            </div><!-- inside -->
        </div><!-- container -->
    </div><!-- wrap -->
<?php $this->renderPartial('/copyright'); ?>
</div> <!-- left-col -->
